 package com.xinlin.common.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinlin.common.service.BaseService;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

 /**
  * @author xinlin
  * @date 2024-11-08
  */
 public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {

//     protected Page setPageParam(QueryParam queryParam) {
//         return setPageParam(queryParam, null);
//     }
//
//
//     protected Page setPageParam(QueryParam queryParam, OrderItem defaultOrder) {
//         Page page = new Page();
//         // 设置当前页码
//         page.setCurrent(queryParam.getCurrent());
//         // 设置页大小
//         page.setSize(queryParam.getSize());
//         /**
//          * 如果是queryParam是OrderQueryParam，并且不为空，则使用前端排序
//          * 否则使用默认排序
//          */
//         if (queryParam instanceof OrderQueryParam) {
//             OrderQueryParam orderQueryParam = (OrderQueryParam) queryParam;
//             List<OrderItem> orderItems = orderQueryParam.getOrders();
//             if (CollectionUtils.isEmpty(orderItems)) {
//                 page.setOrders(Arrays.asList(defaultOrder));
//             } else {
//                 page.setOrders(orderItems);
//             }
//         } else {
//             page.setOrders(Arrays.asList(defaultOrder));
//         }
//
//         return page;
//     }
//
//
//     public void exportExcel(HttpServletResponse response, String[] columnNames, List records, String title) throws IOException {
//         response.reset();
//         response.setHeader("Content-disposition",
//                 "attachment; filename=" + title);
//         //response.setContentType("application/msexcel");
//         response.setContentType("application/vnd.ms-excel;charset=utf-8");
//         ExportExcelUtil exportExcelUtil = new ExportExcelUtil<>();
//         exportExcelUtil.exportExcel(title, columnNames, records, response.getOutputStream(), ExportExcelUtil.EXCEl_FILE_2007);
//     }

 }
